package com.dz.risk.service.impl;

import com.dz.risk.dao.SqlDao;
import com.dz.risk.service.SqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class SqlServiceImpl implements SqlService {
    @Autowired
    private SqlDao sqlDao;
    /**
     * 根据SQL 调用dao 返回计算值
     * @param queryParams
     * @return
     */
    @Override
    public BigDecimal numberation(String queryParams, Date version) {

        if (queryParams.contains("#{version}")){
            //断言 判断版本号
            Assert.notNull(version,"缺少版本号");
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
            String versionFormat = dateFormat.format(version);
            queryParams= queryParams.replace("#{version}",versionFormat);
        }
        BigDecimal numberation = sqlDao.numberation(queryParams);

        return  numberation;
    }
}
